#include "shuttle_shield_item.h"

SHUTTLE_SHIELD_ITEM::SHUTTLE_SHIELD_ITEM(SHIELD_ITEM_TYPE type, CASH *cash):QGraphicsObject()
{
    this->cash = cash;
    this->type = type;

    init();
}

SHUTTLE_SHIELD_ITEM::~SHUTTLE_SHIELD_ITEM(){}

void SHUTTLE_SHIELD_ITEM::paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *){}

QRectF SHUTTLE_SHIELD_ITEM::boundingRect() const
{
    return QRectF();
}

QPainterPath SHUTTLE_SHIELD_ITEM::shape() const
{
    return QPainterPath();
}


void SHUTTLE_SHIELD_ITEM::init()
{
    switch (type) {
    case TL:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/tl.png"), this);
        break;

    case TC:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/tc.png"), this);
        break;

    case TR:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/tr.png"), this);
        break;

    case CL:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/cl.png"), this);
        break;

    case CR:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/cr.png"), this);
        break;

    case DL:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/dl.png"), this);
        break;

    case DC:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/dc.png"), this);
        break;

    case DR:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/dr.png"), this);
        break;

    case FULL:
        item_pix = new GRAPHICS_PIXMAP_ITEM(*cash->cash_pixmap->value(DEF_SHIPS_PATH + "Shuttle/shield/full.png"), this);
        break;

    default:
        break;
    }

    prop_anim = new QPropertyAnimation(this, "transparent", this);
    prop_anim->setDuration(1000);

    this->setOpacity(0);
}


void SHUTTLE_SHIELD_ITEM::blink()
{
    prop_anim->stop();
    prop_anim->setKeyValueAt(0, 0);
    prop_anim->setKeyValueAt(0.3, 1);
    prop_anim->setKeyValueAt(0.45, 0.6);
    prop_anim->setKeyValueAt(0.6, 1);
    prop_anim->setKeyValueAt(1, 0);

    prop_anim->start();
}

//Property
qreal SHUTTLE_SHIELD_ITEM::Transparent()
{
    return this->opacity();
}

void SHUTTLE_SHIELD_ITEM::setTransparent(qreal value)
{
    this->setOpacity(value);
}
